package pdfsetter.core.util;

import java.util.Arrays;

/**
 * This class, as its name says, is extension of class Arrays. Here are methods which are used in other classes and were not implemented in standard Arrays
 * class.
 * 
 * @author Andrzej Dorobisz
 */
public class ArraysExtension {
    /**
     * This is extension of binarySearch from class {@link Arrays}- we search key in given array, and if the key is not found, we return index of the last not
     * grater value.
     */
    public static int floorSearch(int[] table, int key) {
        int index = Arrays.binarySearch(table, key);
        if (index >= 0)
            return index;
        else
            return -(index + 2); // insertionPoint - 1
    }
}
